$(function() {
	$('.menu-delete').on('click', function() {
		$('#del-confirm').modal({
			relatedTarget : this,
			onConfirm : function(options) {
				var id = $(this.relatedTarget).attr("data-id");
				window.location="deleteMenu?id=" + id;
			},
			// closeOnConfirm: false,
			onCancel : function() {

			}
		});
	});
	
	$(".menu-edit-btn").click(function(){
		var id = $(this).attr("data-id");
		var name = $(this).attr("data-name");
		var url = $(this).attr("data-url");
		var pid = $(this).attr("data-pid");
		var icon = $(this).attr("data-icon");
		var index = $(this).attr("data-index");
		init_menu_form(id,name,url,pid,icon,index);
		//$("#menu-add-panel").show();
		$("#add-mune-btn").click();
		
	});
	
	$("#close-btn").click(function(){
		$("#menu-add-panel-close").click();
	});
	
	$("#menu-add-panel-close").click(function(){
		reset_menu_form();
	});
	
	$("#sub-btn").click(function() {
		var menuname = $("#menuname");
		if(check_menuname(menuname)){
			$("#menu-form").submit();
		}
	});
	/*
	 * 重置表单
	 * */
	function reset_menu_form(){
		init_menu_form("","","",0,"",0);
	}
	/*
	 * 初始化表单内容
	 * */
	function init_menu_form(id,name,url,parentId,icon,index){
		$("#menu-id").val(id);
		$("#menuname").val(name);
		$("#menuurl").val(url);
		$("#pid-select").val(parentId);
		$("#menuicon").val(icon);
		$("#menuindex").val(index);
	}
	
	function check_menuname(menunameObj) {
		var menuname = menunameObj.val();
		var result = true;
		if(menuname == ""){
			alert("请填写菜单名称");
			result = false;
		}
		return result;
	}
});